home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / 80x0393.zip / COPRO.ASM < prev    next >
Assembly Source File  |  1993-06-20  |  7KB  |  252 lines

  1. comment *
  2.    Purpose:
  3.    To detect math coprocessor type (8087, 287, 387) and manufacturer
  4.    (Intel, IIT)
  5.  
  6.    Author:
  7.    Yousuf Khan. Source code based partly on Infoplus source code by
  8.    Andrew Rossman, IIT detection routines entirely my own. Infoplus is
  9.    freeware, therefore this source code is released as freeware,
  10.    not public domain. Original authors must be acknowledged in any
  11.    future work.
  12. *
  13.  
  14.         .model  tiny
  15.  
  16.         .data
  17.         fnone   equ     0
  18.         f8087   equ     1
  19.         f80287  equ     2
  20.         f80387  equ     3
  21.         funk    equ     0FFh
  22.         ndp_cw  dw      ?
  23.         ndp_sw  dw      ?
  24.         mNDPCW  dw      ?
  25.         mndp    db      ?
  26.         ndpmsg  db      "Math coprocessor found: $"
  27.         manmsg  db      "Manufacturer: $"
  28.         _87     db      "8087",13,10,"$"
  29.         _287    db      "80287",13,10,"$"
  30.         _387    db      "80387 or i486",13,10,"$"
  31.         _funk   db      "What the hell kind of a copro is this?",13,10,"$"
  32.         Intel   db      "Intel or clone",13,10,"$"
  33.         IIT     db      "IIT or clone",13,10,"$"
  34.  
  35.         .code
  36.         org     100h
  37.  
  38. start:
  39.  
  40. ; The next two 80x87 instructions cannot carry the WAIT prefix,
  41. ; because there may not be an 80x87 for which to wait.  The WAIT is
  42. ; therefore emulated with a MOV CX,<value>! LOOP $ combination.
  43.  
  44. .8087
  45.         mov     word ptr ndp_cw,0000H
  46.         cli                     ;no interrupts during this test
  47.  
  48.         fninit                  ;initialize NDP
  49.         mov     cx,2
  50.         loop    $
  51.  
  52.         fnstcw  ndp_cw          ;store control word in ndp_cw
  53. ;        mov     cx,14h
  54. ;        loop    $
  55.  
  56.         sti
  57.         mov     ax,ndp_cw       ;check for valid status word
  58.         cmp     ah,3            ;is NDP present?
  59.         je      short ndp_01    ;if 3, must be there
  60.         mov     mNDP,fnone
  61.         jmp     short ndp_done
  62.  
  63. ndp_01:
  64.         cmp     ax,03FFH        ;check if 8087
  65.         jne     short ndp_02
  66.         mov     mNDP,f8087
  67.         jmp     short ndp_04
  68.  
  69. ndp_02:
  70.         call    iit_test
  71.  
  72. .286P
  73.         cmp     ax,037FH        ;check if 286/387/486
  74.         jne     short ndp_05    ;must be garbage
  75.  
  76. ;detect 287 or 387
  77.  
  78.         fld1                    ;Load +1.0 onto NDP stack
  79.         fldz                    ;Load +0.0 onto NDP stack
  80.         fdiv                    ;do +1/0
  81.         fld1                    ;Load +1.0 onto NDP stack
  82.         fchs                    ;Change to -1.0
  83.         fldz                    ;Load +0.0 onto NDP stack
  84.         fdiv                    ;do -1/0
  85.         fcom                    ;compare
  86.         fstsw   ndp_sw
  87.         mov     ax,ndp_sw
  88.         and     ah,41H          ; C3, C0
  89.         cmp     ah,40H          ; ST(0) = ST(1)
  90.         jne     short ndp_03
  91.         mov     mNDP,f80287
  92.         jmp     short ndp_04
  93.  
  94. ndp_03:
  95.         cmp     ah,01H          ; ST(0) < ST(1)
  96.         jne     short ndp_05
  97.         mov     mNDP,f80387
  98.  
  99. ndp_04:
  100.  
  101. .8087
  102.         fstcw   mNDPCW          ;save status for INFOPLUS
  103.         jmp     short ndp_done
  104.  
  105. ndp_05:
  106.         mov     mNDP,funk
  107.  
  108. ndp_done:
  109.         mov     ah, 9
  110.         mov     dx, offset manmsg
  111.         int     21h
  112.         cmp     [mman], 1       ;IIT=1?
  113.         jne     short intelman
  114.         mov     ah, 9
  115.         mov     dx, offset iit
  116.         int     21h
  117.         jmp     short type_msgs
  118.  
  119. intelman:
  120.         mov     ah, 9
  121.         mov     dx, offset intel
  122.         int     21h
  123.  
  124. type_msgs:
  125.         mov     ah, 9
  126.         mov     dx, offset ndpmsg
  127.         int     21h
  128.         cmp     [mndp], 0FFh
  129.         jne     short not_funk
  130.         mov     ah, 9
  131.         mov     dx, offset _funk
  132.         int     21h
  133.         jmp     short exit_prog
  134.  
  135. not_funk:
  136.         cmp     [mndp], 3
  137.         jne     short not_387
  138.         mov     ah, 9
  139.         mov     dx, offset _387
  140.         int     21h
  141.         jmp     short exit_prog
  142.  
  143. not_387:
  144.         cmp     [mndp], 2
  145.         jne     short not_287
  146.         mov     ah, 9
  147.         mov     dx, offset _287
  148.         int     21h
  149.         jmp     short exit_prog
  150.  
  151. not_287:
  152.         mov     ah, 9
  153.         mov     dx, offset _87
  154.         int     21h
  155. exit_prog:
  156.         mov     al, [mndp]
  157.         mov     ah, 4ch
  158.         int     21h
  159.  
  160. iit_test        proc    near
  161.  
  162.         .data
  163.         fsb0    equ     <dw 0E8DBh>     ;bank 0 opcode
  164.         fsb1    equ     <dw 0EBDBh>     ;bank 1 opcode
  165.         fsb2    equ     <dw 0EADBh>     ;bank 2 opcode
  166.         f4x4    equ     <dw 0F1DBh>     ;4x4 mat transform opcode
  167.         f0      dd      9.9999
  168.         f1      dd      10.0
  169.         mman    db      0       ;assume Intel=0 installed initially
  170.  
  171.         .code
  172.         ;initialize two banks to zero
  173.         wait
  174.         fsb0            ;switch to bank 0, default on Intel
  175.         finit
  176.         fsb1            ;switch to bank 1
  177.         finit
  178.         ;store a 2.0 into bank 0 while placing a 1.0 into bank 1
  179.         fsb0            ;switch to bank 0
  180.         fld     [f0]    ;load value from [F2] into bank 0 stack
  181.         fclex           ;clear all math copro exceptions
  182.  
  183.         fsb1            ;switch to bank 1, should fail on Intel
  184.         fld     [f1]    ;load a 1 into bank 1 stack
  185.         fclex
  186.  
  187.         fsb0
  188.         fcom    [f0]    ;compare, should be false on Intel
  189.         fclex
  190.  
  191.         push    ax
  192.         .286p           ;FNSTSW AX only works on 287+
  193.         fnstsw  ax      ;store stat word in AX
  194.         sahf            ;transfer copro flags to CPU flags
  195.         ja      short is_intel
  196.         mov     [mman], 1       ;IIT=1, Intel=0 (default)
  197.  
  198. is_intel:
  199.         finit           ;reset to original
  200.         pop     ax
  201.         ret
  202.         endp
  203.         end     start
  204.  
  205.  
  206. iit_test        proc    near
  207.  
  208.         .data
  209.         fsb0    equ     <dw 0E8DBh>     ;bank 0 opcode
  210.         fsb1    equ     <dw 0EBDBh>     ;bank 1 opcode
  211.         fsb2    equ     <dw 0EADBh>     ;bank 2 opcode
  212.         f4x4    equ     <dw 0F1DBh>     ;4x4 mat transform opcode
  213.         f0      dd      9.9999
  214.         f1      dd      10.0
  215.         mman    db      0       ;assume Intel=0 installed initially
  216.  
  217.         .code
  218.         ;initialize two banks to zero
  219.         wait
  220.         fsb0            ;switch to bank 0, default on Intel
  221.         finit
  222.         fsb1            ;switch to bank 1
  223.         finit
  224.         ;store a 2.0 into bank 0 while placing a 1.0 into bank 1
  225.         fsb0            ;switch to bank 0
  226.         fld     [f0]    ;load value from [F2] into bank 0 stack
  227.         fclex           ;clear all math copro exceptions
  228.  
  229.         fsb1            ;switch to bank 1, should fail on Intel
  230.         fld     [f1]    ;load a 1 into bank 1 stack
  231.         fclex
  232.  
  233.         fsb0
  234.         fcom    [f0]    ;compare, should be false on Intel
  235.         fclex
  236.  
  237.         push    ax
  238.         .286p           ;FNSTSW AX only works on 287+
  239.         fnstsw  ax      ;store stat word in AX
  240.         sahf            ;transfer copro flags to CPU flags
  241.         ja      short is_intel
  242.         mov     [mman], 1       ;IIT=1, Intel=0 (default)
  243.  
  244. is_intel:
  245.         finit           ;reset to original
  246.         pop     ax
  247.         ret
  248.         endp
  249.         end     start
  250.  
  251. ; EOF COPRO.ASM
  252.